<?php
/*
 * 返回json格式数据
 */
function show($data=[],$status=1,$msg="获取成功"){
    return json(['data'=>$data,'status'=>$status,'msg'=>$msg]);
}

/*
 * 经纬度计算  km
 */
function getdistance($lng1, $lat1, $lng2, $lat2) {
    $radLat1 = deg2rad($lat1);
    $radLat2 = deg2rad($lat2);
    $radLng1 = deg2rad($lng1);
    $radLng2 = deg2rad($lng2);
    $a = $radLat1 - $radLat2;
    $b = $radLng1 - $radLng2;
    $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137;
    return round($s,1);
}

function randomkeys($length){
    $key='';
    $pattern = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for($i=0;$i<$length;$i++)
    {
        $key .= $pattern{mt_rand(0,35)};
    }
    return $key;

}
